package com.pixelengine.Task26Oee;

import com.google.gson.Gson;
import com.google.gson.stream.JsonReader;

import java.io.FileReader;
import java.util.HashMap;

public class ProductInfos {
    public class ProductInfo {
        public String pdtname;
        public String proj;
        public int minZoom=0;
        public int maxZoom=0;
        //1-byte,2-u16,3-i16,4-u32,5-i32,6-f32,7-f64
        public int dataType=1;
        public int timeType=1;
        public String hTableName;
        public int tileWid=256;
        public int tileHei=256;
        public String compress;
        public int nbands=0;
        public int styleid=0;
        public double nodata = 0 ;
        public String filenameTemplate ;
        public int resampleAlg = 0 ;//0-near 1-bilinear 2-cubic 3-cubicSpline
    }

    public ProductInfo[] product_array = null ;
    public HashMap<String,ProductInfo> productDict = new HashMap<String,ProductInfo>();

    public static boolean init(String jsonfilename) {
        try{
            JsonReader reader = new JsonReader(new FileReader(jsonfilename)) ;
            ProductInfos tempInst = new ProductInfos();
            Gson gson = new Gson() ;
            tempInst = gson.fromJson(reader,ProductInfos.class) ;
            for(int i = 0 ; i<tempInst.product_array.length;++i ) {
                tempInst.productDict.put(
                        tempInst.product_array[i].pdtname,
                        tempInst.product_array[i]) ;
            }
            _s_instance = tempInst ;
            return true;
        }catch (Exception e) {
            return false;
        }
    }
    public static ProductInfos getInstance(){return _s_instance ;}
    private static ProductInfos _s_instance = null ;

}

//"pdtname": "MODIS/MOD09CMG",
//        "proj": "EPSG:4326",
//        "minZoom": 0,
//        "maxZoom": 5,
//        "dataType": 3,
//        "timeType": 5,
//        "hTableName": "notused",
//        "tileWid": 256,
//        "tileHei": 256,
//        "compress": "no",
//        "styleid": 0,
//        "nodata":0
//        }